

import 'package:utils/util/utils_path.dart';
import 'package:logger/logger.dart';

class Print {
  static const VERBOSE = 2;
  static const DEBUG = 3;
  static const INFO = 4;
  static const WARN = 5;
  static const ERROR = 6;

  static Print _instance = Print._internal();
  static bool debug = true;
  static int level = VERBOSE;
  Logger _logger;

  factory Print() {
    return _instance;
  }

  Print._internal();

  /// 调试日志
  void printDebug(Object object) => printNative(object, level: DEBUG);

  /// 错误日志
  void printError(Object object) => printNative(object, level: ERROR);

  /// 警告日志
  void printWarn(Object object) => printNative(object, level: WARN);

  /// 开发日志
  void printInfo(Object object) => printNative(object, level: INFO);

  void printNative(Object object, {int level: VERBOSE}) {
    if (Print.level > level) {
      return;
    }

    if (debug) {
      Level l = Level.debug;
      switch (level) {
        case VERBOSE:
          l = Level.verbose;
          break;
        case INFO:
          l = Level.info;
          break;
        case WARN:
          l = Level.warning;
          break;
        case ERROR:
          l = Level.error;
          break;
      }
      if (_logger == null) {
        _logger = new Logger(printer: PrettyPrinter(methodCount: 2), level: l);
      }
      _logger.log(l, object);
    }
  }
}
